package controllayer;

import static org.junit.Assert.*;
import modellayer.Item;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * The Class ItemControllerTest.
 *@author Benjamin Ørskov
 *@author Lasse Lambertsen
 *@author Ole Kirk
 *@author Søren Søgaard
 */
public class ItemControllerTest {
	/** The item co1. */
	controllayer.ItemController itemCo1 = new controllayer.ItemController();

	/**
	 * Sets the up.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@Before
	public void setUp() throws Exception {
		itemCo1.createItem("Skrue", 1, 10.0, 1000);
		itemCo1.createItem("Skruetrækker", 2, 50.0, 500);
	}

	/**
	 * Tear down.
	 *
	 * @throws Exception
	 *             the exception
	 */
	@After
	public void tearDown() throws Exception {
		itemCo1.removeItem(1);
		itemCo1.removeItem(2);
	}

	/**
	 * Test method for {@link controllayer.ItemController#findItem(int)}.
	 */
	@Test
	public void testFindItem() {
		assertEquals("Skrue", itemCo1.findItem(1).getType());
		try {
			itemCo1.findItem(5);
		} catch (NullPointerException npe) {
			assertEquals("Varen blev ikke fundet!", npe.getMessage());
		}
	}

	/**
	 * Test method for {@link controllayer.ItemController#removeItem(int)}.
	 */
	@Test
	public void testRemoveItem() {
		itemCo1.removeItem(1);
		try {
			itemCo1.findItem(1);
		} catch (NullPointerException npe) {
			assertEquals("Varen blev ikke fundet!", npe.getMessage());
		}
		itemCo1.createItem("Skrue", 1, 10.0, 1000);
	}

	/**
	 * Test method for
	 * {@link controllayer.ItemController#updateItem(modellayer.Item, java.lang.String, java.lang.Integer, java.lang.Double, java.lang.Integer)}
	 * .
	 */
	@Test
	public void testUpdateItem() {
		Item tempI = itemCo1.findItem(1);
		itemCo1.updateItem(tempI, "Torxskrue", 1, 10.0, 1000);
		assertEquals("Torxskrue", itemCo1.findItem(1).getType());
	}

}
